package timbap.visualizer.api.plugin.container;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import timbap.visualizer.api.model.RecordItem;
import timbap.visualizer.api.plugin.Plugin;
import timbap.visualizer.api.plugin.recorditems.RecordItemsPlugin;

/**
 * The <code>AbstractItemsPluginFork</code> provides a base
 * implementation for plugin forks that contain only record
 * item drawing plugins.
 * It delegates the <code>draw()</code> call to calls of their
 * <code>drawRecordItem(RecordItem)</code> method for every
 * record item.
 *
 * @author  Andreas Pabst
 * @see     timbap.visualizer.api.plugin.recorditems.RecordItemsPlugin
 * @see     timbap.visualizer.api.plugin.container.AbstractPluginFork
 * @see     timbap.visualizer.api.plugin.container.AbstractGlobalPluginFork
 * @see     timbap.visualizer.api.plugin.container.AbstractMixedPluginFork
 */
public abstract class AbstractRecordItemsPluginFork extends AbstractPluginFork {

	private static final Log LOG = LogFactory.getLog(AbstractRecordItemsPluginFork.class);
    
	public void draw() {

    	for (RecordItem tRecordItem: getContext().getRecordItemManager().getRecordItems()) {
    		for (Plugin tPlugin: getPlugins()) {
    			if (tPlugin instanceof RecordItemsPlugin) {
    				RecordItemsPlugin tRecordItemsPlugin = (RecordItemsPlugin)tPlugin;
	                if (tRecordItemsPlugin.isVisualizationNecessary(tRecordItem)) {
	    			    tRecordItemsPlugin.drawRecordItem(tRecordItem);
	    			}
    			} else {
    				LOG.warn("The plugin " + tPlugin + " is not a record items plugin,"
    						+ "but has been added to the record items plugin fork " + this + ".");
    			}
    		}
    	}
	}
	
}
